package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.TheGeography;
import com.ruoyi.system.service.ITheGeographyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * geographyController
 * 
 * @author ruoyi
 * @date 2023-04-17
 */
@RestController
@RequestMapping("/system/geography")
public class TheGeographyController extends BaseController
{
    @Autowired
    private ITheGeographyService theGeographyService;

    /**
     * 查询geography列表
     */
    @PreAuthorize("@ss.hasPermi('system:geography:list')")
    @GetMapping("/list")
    public TableDataInfo list(TheGeography theGeography)
    {
        startPage();
        List<TheGeography> list = theGeographyService.selectTheGeographyList(theGeography);
        return getDataTable(list);
    }

    /**
     * 导出geography列表
     */
    @PreAuthorize("@ss.hasPermi('system:geography:export')")
    @Log(title = "geography", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TheGeography theGeography)
    {
        List<TheGeography> list = theGeographyService.selectTheGeographyList(theGeography);
        ExcelUtil<TheGeography> util = new ExcelUtil<TheGeography>(TheGeography.class);
        util.exportExcel(response, list, "geography数据");
    }

    /**
     * 获取geography详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:geography:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(theGeographyService.selectTheGeographyById(id));
    }

    /**
     * 新增geography
     */
    @PreAuthorize("@ss.hasPermi('system:geography:add')")
    @Log(title = "geography", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TheGeography theGeography)
    {
        return toAjax(theGeographyService.insertTheGeography(theGeography));
    }

    /**
     * 修改geography
     */
    @PreAuthorize("@ss.hasPermi('system:geography:edit')")
    @Log(title = "geography", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TheGeography theGeography)
    {
        return toAjax(theGeographyService.updateTheGeography(theGeography));
    }

    /**
     * 删除geography
     */
    @PreAuthorize("@ss.hasPermi('system:geography:remove')")
    @Log(title = "geography", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(theGeographyService.deleteTheGeographyByIds(ids));
    }

    @GetMapping("/test")
    public AjaxResult readCsv(){
        String filePath = "D:\\earthquake.csv";
        try {
            theGeographyService.readCsv(filePath);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        return toAjax(200);
    }

}
